<?php
namespace Home\Controller;
use Think\Controller;
class CaseController extends Controller {
    public function index(){
        $uid=session('uid');
        $news=M('news')->where(array("top"=>1))->select();
        $this->news=$news;
        /*dump($news);*/
         /*  exit();*/
        if(!$uid)
        {$this->error('登录已过期!',U("Home/Login/index"));}
        elseif($news){
            $this->assign('list', $news);
            $this->display();
        }
        else{ $this->error('获取失败!', U("Home/Index/index"));}
    }
    public function detail(){
        $id = $_GET['id'];
        $newsmodel=M('news');
        $news=$newsmodel->where(array("id" => $id))->join('users on users.uid=news.n_uid')->select();

        for ($i = 0; $i < count($news); $i++){

            if($news[$i]["tid"]== 1){
                $type[$i]='体育';
            }
            elseif($news[$i]["tid"]== 2)
            {
                $type[$i]='时政';

            }
            elseif($news[$i]["tid"]== 3)
            {
                $type[$i]='娱乐';

            }
            elseif($news[$i]["tid"]== 4)
            {
                $type[$i]='科技';

            }

            elseif($news[$i]["tid"]== 5)
            {
                $type[$i]='军事';

            }
            elseif($news[$i]["tid"]== 6)
            {
                $type[$i]='游戏';

            }
            elseif($news[$i]["tid"]== 7)
            {
                $type[$i]='视频';

            }
            $news[$i]["tid"]=$type[$i];
        }
        if($news){
            $this->assign('list', $news);
            $this->display();
        }
        else{ $this->error('获取失败!', U("Home/Casedetail/index"));}
    }
}